package com.coda.clouddisk.config;

import com.coda.clouddisk.interceptor.JwtTokenInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;


@Configuration
@Slf4j
public class WebMvcConfig extends WebMvcConfigurationSupport {

    @Autowired
    private JwtTokenInterceptor jwtTokenInterceptor;

    /**
     * 自定义资源映射
     */
    @Override
    protected void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/**").addResourceLocations(
                "classpath:/static/");
        registry.addResourceHandler("swagger-ui.html", "doc.html").addResourceLocations(
                "classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**").addResourceLocations(
                "classpath:/META-INF/resources/webjars/");
        super.addResourceHandlers(registry);
    }

    /**
     * swagger接口文档
     */
//    public Docket docket() {
//        ApiInfo apiInfo = new ApiInfoBuilder()
//                .title("现代网盘接口文档")
//                .version("2.0")
//                .description("现代网盘接口文档")
//                .build();
//        Docket docket = new Docket(DocumentationType.SWAGGER_2)
//                .groupName("接口管理")
//                .apiInfo(apiInfo)
//                .select()
//                .apis(RequestHandlerSelectors.basePackage("com.jxxd.clouddisk.controller.impl"))
//                .paths(PathSelectors.any())
//                .build();
//        return docket;
//    }

    /**
     * 注册自定义拦截器
     */
    protected void addInterceptors(InterceptorRegistry registry) {
        log.info("开始注册自定义员工拦截器...");
        registry.addInterceptor(jwtTokenInterceptor)
                .addPathPatterns("/clouddisk/**")
                .excludePathPatterns("/clouddisk/user/login")
                .excludePathPatterns("/clouddisk/user/register");

    }
}
